package kokonut.shop.product;

import java.util.ArrayList;

import javax.jdo.annotations.Inheritance;
import javax.jdo.annotations.InheritanceStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;

import kokonut.shop.color.Color;
import kokonut.shop.size.Size;
//import kokonut.shop.stock.StockInfo;

@PersistenceCapable
@Inheritance(strategy = InheritanceStrategy.NEW_TABLE)
public class TShirtModel extends Model {

    @Persistent
    private ArrayList<Size> availableSizes;
    @Persistent
    private ArrayList<Color> availableColors;
    @Persistent
    private ArrayList<Image> modelImages;

    //TODO Implementar sistema de Stock
//	@Persistent
//	private ArrayList<StockInfo> stockInfo;
    public TShirtModel() {
    }

    public TShirtModel(int ref, String name, ArrayList<Size> availableSizes, ArrayList<Color> availableColors,
            ArrayList<Image> images) {
        super(ref, name);
        this.availableColors = availableColors;
        this.availableSizes = availableSizes;
        this.modelImages = images;
        //this.stockInfo = new ArrayList<StockInfo>();
//		for(Size s:availableSizes)
//			for(Color c:availableColors)
//			{
//				StockInfo info = new StockInfo(s.getSize(), c.getColor(), 0);
//				this.stockInfo.add(info);
//			}
    }

    public ArrayList<Size> getAvailableSizes() {
        return availableSizes;
    }

    public void setAvailableSizes(ArrayList<Size> availableSizes) {
        this.availableSizes = availableSizes;
    }

    public ArrayList<Color> getAvailableColors() {
        return availableColors;
    }

    public void setAvailableColors(ArrayList<Color> availableColors) {
        this.availableColors = availableColors;
    }

    public float getPriceBySize(String sizeName) {
        if (availableSizes != null) {
            for (Size size : availableSizes) {
                if (size.getSize().name().equals(sizeName)) {
                    return size.getPrice();
                }
            }
        }
        return 0;
    }

    public int getStockBySize(String sizeName) {
        if (availableSizes != null) {
            for (Size size : availableSizes) {
                if (size.getSize().name().equals(sizeName)) {
                    return size.getStock();
                }
            }
        }
        return 0;
    }

//	public void setStockInfo(ArrayList<StockInfo> stockInfo) {
//		this.stockInfo = stockInfo;
//	}
//
//	public ArrayList<StockInfo> getStockInfo() {
//		return stockInfo;
//	}
//
//	public void updateStockInfo(int ref, String size, String color, int stock) {
//		for(int i = 0; i<this.stockInfo.size();i++)
//		{
//			StockInfo info = this.stockInfo.get(i);
//			if(info.getSize().name().equals(size) && info.getColor().name().equals(color))
//			{
//				info.setStock(stock);
////				this.stockInfo.set(i, info);   ------> No era necesario
//			}
//		}
//	}
    public ArrayList<Image> getModelImages() {
        return modelImages;
    }

    public void setModelImages(ArrayList<Image> modelImages) {
        this.modelImages = modelImages;
    }

    public boolean hasThisColorImage(String color) {
        for(Image img : this.modelImages){
            if(img.getDescription().equals(color))
                return true;
        }
        return false;
    }


    public boolean hasS() {
        if (availableSizes != null) {
            for (Size size : availableSizes) {
                if (size.getSize().name().equals("S")) {
                    return true;
                }
            }
        }
        return false;
    }

    public boolean hasM() {
        if (availableSizes != null) {
            for (Size size : availableSizes) {
                if (size.getSize().name().equals("M")) {
                    return true;
                }
            }
        }
        return false;
    }

    public boolean hasL() {
        if (availableSizes != null) {
            for (Size size : availableSizes) {
                if (size.getSize().name().equals("L")) {
                    return true;
                }
            }
        }
        return false;
    }

    public boolean hasXL() {
        if (availableSizes != null) {
            for (Size size : availableSizes) {
                if (size.getSize().name().equals("XL")) {
                    return true;
                }
            }
        }
        return false;
    }

    public boolean hasXXL() {
        if (availableSizes != null) {
            for (Size size : availableSizes) {
                if (size.getSize().name().equals("XXL")) {
                    return true;
                }
            }
        }
        return false;
    }

    public boolean hasWhite() {
        if (availableColors != null) {
            for (Color color : availableColors) {
                if (color.getColor().name().equals("WHITE")) {
                    return true;
                }
            }
        }
        return false;
    }

    public boolean hasYellow() {
        if (availableColors != null) {
            for (Color color : availableColors) {
                if (color.getColor().name().equals("YELLOW")) {
                    return true;
                }
            }
        }
        return false;
    }

    public boolean hasOrange() {
        if (availableColors != null) {
            for (Color color : availableColors) {
                if (color.getColor().name().equals("ORANGE")) {
                    return true;
                }
            }
        }
        return false;
    }

    public boolean hasRed() {
        if (availableColors != null) {
            for (Color color : availableColors) {
                if (color.getColor().name().equals("RED")) {
                    return true;
                }
            }
        }
        return false;
    }

    public boolean hasBrown() {
        if (availableColors != null) {
            for (Color color : availableColors) {
                if (color.getColor().name().equals("BROWN")) {
                    return true;
                }
            }
        }
        return false;
    }

    public boolean hasBlue() {
        if (availableColors != null) {
            for (Color color : availableColors) {
                if (color.getColor().name().equals("BLUE")) {
                    return true;
                }
            }
        }
        return false;
    }

    public boolean hasGreen() {
        if (availableColors != null) {
            for (Color color : availableColors) {
                if (color.getColor().name().equals("GREEN")) {
                    return true;
                }
            }
        }
        return false;
    }

    public boolean hasPurple() {
        if (availableColors != null) {
            for (Color color : availableColors) {
                if (color.getColor().name().equals("PURPLE")) {
                    return true;
                }
            }
        }
        return false;
    }

    public boolean hasPink() {
        if (availableColors != null) {
            for (Color color : availableColors) {
                if (color.getColor().name().equals("PINK")) {
                    return true;
                }
            }
        }
        return false;
    }

    public boolean hasGrey() {
        if (availableColors != null) {
            for (Color color : availableColors) {
                if (color.getColor().name().equals("GREY")) {
                    return true;
                }
            }
        }
        return false;
    }

    public boolean hasBlack() {
        if (availableColors != null) {
            for (Color color : availableColors) {
                if (color.getColor().name().equals("BLACK")) {
                    return true;
                }
            }
        }
        return false;
    }
}
